#include "stdafx.h"

#include "common.h"

std::wstring ConvertStringToUnicode(const char* cstr)
{
	std::wstring ret = L"";

	if (!cstr || cstr[0] == '\0') 
		return ret;

	wchar_t *wstr = NULL;

	int elem = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cstr, -1, NULL, 0);
	if (!elem) 
		return ret;

	wstr = new wchar_t[elem + 1];
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, cstr, -1, wstr, elem);
	ret = wstr;
	delete []wstr;

	return ret;
};

std::string ConvertUnicodeToString(std::wstring wstr)
{
	std::string ret = "";
	if (wstr.length() == 0)
		return ret;

	char *cstr = NULL;
	int elem = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
	if (!elem) 
		return ret;

	cstr = new char[elem + 1];
	WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, cstr, elem, NULL, NULL);
	ret = cstr;
	delete []cstr;

	return ret;
};

std::wstring ConvertIntToUnicode(int number)
{
	std::wstring ret = L"";
	wchar_t tmp[20];
	wsprintf(tmp, L"%d", number);
	ret = tmp;
	return ret;
};